using System;

namespace KTOP.Core.Domain.Matrix
{
    public class DMatrix : MatrixWithSumms
    {
        public DMatrix(int[][] matrix)
            : base(matrix)
        {
        }

        public static DMatrix CreateFromBoardPlacer(BoardPlacer placer)
        {
            var dMatrix = CreateEmptyMatrix(placer.ModuleCount);

            for (var row = 0; row < placer.ModuleCount; row++)
            {
                for (var col = 0; col < placer.ModuleCount; col++)
                {
                    if (col == row) continue;

                    var rPos = placer.GetBoardPosition(row);
                    var cPos = placer.GetBoardPosition(col);

                    dMatrix[row][col] = Math.Abs(rPos.X - cPos.X) + Math.Abs(rPos.Y - cPos.Y);
                }
            }

            return new DMatrix(dMatrix);
        }
    }
}